﻿using Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleTest.tt
{
    public partial class ControllerTemplate
    {
        private TableInfo tableInfo;

        public string ClassName => tableInfo.TableName;

        public string ModelName => tableInfo.TableName.ToLower();

        public string Comment => tableInfo.Comment;

        public string PKField
        {
            get
            {
                var f = tableInfo.StructFields.FirstOrDefault(x => x.IsPrimaryKey);
                if (f == null)
                    return "";
                else
                    return f.FieldName;
            }
        }

        public string PKType
        {
            get
            {
                var t = "string";
                var f = tableInfo.StructFields.FirstOrDefault(x => x.IsPrimaryKey);
                if (f == null)
                    return "string";
                else
                {
                    switch (f.FieldType)
                    {
                        case FieldTypeEnum.String:
                            t = "string";
                            break;
                        case FieldTypeEnum.Int:
                            t = "int";
                            break;
                        case FieldTypeEnum.Decimal:
                            t = "decimal";
                            break;
                        case FieldTypeEnum.Float:
                            t = "float";
                            break;
                        case FieldTypeEnum.Double:
                            t = "double";
                            break;
                        case FieldTypeEnum.Long:
                            t = "long";
                            break;
                        case FieldTypeEnum.DateTime:
                            t = "DateTime";
                            break;
                        default:
                            break;
                    }
                }
                return t;
            }
        }

        public ControllerTemplate(TableInfo tableInfo)
        { 
            this.tableInfo = tableInfo;
        }
    }
}
